-
Notifications
You must be signed in to change notification settings - Fork 814
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Text input improvements #528
Conversation
…r was attempting to be applied when no text visible
… calculates suffix
elif key == "home" or key == "ctrl+a": | ||
self._editor.cursor_text_start() | ||
elif key == "end": | ||
elif key == "end" or key == "ctrl+e": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding these standard terminal keybindings made me think about how these could clash with app-level keybindings. Should there be a standard way to say "for this instance of a widget, ignore this keybinding"?
I'm picturing an application that has "ctrl+a" to open some menu, and the user is currently focussed on a text input. Do they want to open the menu or do they want to move their cursor home? Do they want both? Do we offer Textual app authors the flexibility to choose what happens (and if so, how)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...or would the user expects to have a "closer to a text edition context" behaviours, where "ctrl+a" for example selects the whole text instead?
Definitely not easy to figure out what would be the option that would fit the "principle of least surprise" for most users! 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this be solved with bindings and actions? Bindings adds this layer of indirection, so the dev can decide what happens.
But this does feel like something we can figure out later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! 🤩
I only have a very little comment regarding the call to time.monotonic()
:-)
elif key == "home" or key == "ctrl+a": | ||
self._editor.cursor_text_start() | ||
elif key == "end": | ||
elif key == "end" or key == "ctrl+e": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...or would the user expects to have a "closer to a text edition context" behaviours, where "ctrl+a" for example selects the whole text instead?
Definitely not easy to figure out what would be the option that would fit the "principle of least surprise" for most users! 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great. A few comments.
"""Manages the blinking of the cursor - ensuring blinking only starts when the | ||
user hasn't pressed a key in some time""" | ||
if time.monotonic() - self._last_keypress_time > self.cursor_blink_period: | ||
self._cursor_blink_visible = not self._cursor_blink_visible |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this, or could it be, a Reactive value? In that case you wouldn't need the explicit refresh.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think sometimes we set this value and don't want a refresh (because code which follows shortly after refreshes anyway) so it'd be an extra refresh that isn't required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The refreshes are always done on idle, so if you set reactive values and call refresh()
explicitly, Textual will only repaint the screen once.
Another pass through text input which adds:
text-input-filesearch-dogfood.mov